package photobox.account


class User {
    String  username
    String  nickName   //昵称
    String  realName       //真实姓名


    String  password //不保存密码
    String  passwordConfirm
    String  passwordHash

    Integer  isPhotographer = IS_PHOTOGRAPHER_NO //是否为摄影师，摄影师有自己的后台可以上传图片

    String  email
    Boolean enabled
    Integer gender = GENDER_MALE

    String   presentation //自我介绍
    String   photoImage   //头像存储路径


    static final int GENDER_MALE = 0
    static final int GENDER_FEMALE =1


    static final int  IS_PHOTOGRAPHER_NO = 0
    static final int  IS_PHOTOGRAPHER_YES = 1

    static hasMany = [address: Address]
    static transients = ['password', 'passwordConfirm']

    static mapping = {
        table 'acc_user'
    }

    static constraints = {
        username  size:2..30, blank: false, unique: true
        isPhotographer inList: [IS_PHOTOGRAPHER_NO, IS_PHOTOGRAPHER_YES]
        nickName  size: 0..30, unique: true
        realName  nullable: true, size: 0..30
        password  size: 6..12, blank: false
        passwordHash  maxSize: 200
        email email: true, size: 0..200, blank: false
        gender  inList: [GENDER_MALE, GENDER_FEMALE]
        presentation size:1..300, nullable:true
        photoImage  nullable:true

        passwordConfirm   validator: { val, obj, err ->
            if (obj.password != null && val != obj.password) {
                err.rejectValue('passwordConfirm', 'confirmNoMatch',  "两次输入的口令不一致")
            }
        }
    }

}
